﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IAddress))]
    public partial class Address:Entity, IAddress
    {
        #region IAddress Members

        //ICustomer _Customer2;
        //ICustomer IAddress.Customer
        //{
        //    get
        //    {
        //        if (this._Customer2 == null)
        //        {
        //            this._Customer2 = this.DataContext.Customers
        //                .Where(i => i.Id == this.CustomerId)
        //                .FirstOrDefault();
        //        }

        //        return this._Customer2;
        //    }
        //    set
        //    {

        //        if (value == null)
        //        {
        //            throw new NullReferenceException("Customer is null for Adress" + this.Id);
        //        }
        //        this._Customer2 = value;


        //        this.CustomerId = value.Id;
        //    }
        //}


        ICountry _Country2;
        ICountry IAddress.Country
        {
            get
            {
                if (this._Country2 == null)
                {
                    this._Country2 = this.DataContext.Countries
                        .Where(i => i.CountryCode == this.CountryCode)
                        .Select(i => i as ICountry)
                        .FirstOrDefault();
                }

                return this._Country2;
            }
            set
            {
                this._Country2 = value;
                if (value == null)
                {
                    this.CountryCode = null;
                }
                else
                {
                    this.CountryCode = value.CountryCode;
                }
            }
        }

        #endregion
    }
}
